
proc fibonacci {fib_list} {
    # 'upvar' rebinds a variable to one in a different scope.
    # Essentially it takes a variable name, references it, and then binds that
    # referenced variable to a new, local name.
    upvar $fib_list fib_ref
    set prev1 [lindex $fib_ref 0]
    set prev2 [lindex $fib_ref 1]
    set fib [expr $prev1 + $prev2]
    set original_prev2 $prev2

    lset fib_ref 0 $fib
    lset fib_ref 1 $prev1

    return $original_prev2
}

set master_fib_list [concat 1 0]

for {set x 0} {$x < [lindex $argv 0]+1} {incr x} {
    puts -nonewline "[fibonacci master_fib_list] "
}
puts ...
